# -*- coding:utf-8 -*-  

import web

from sys import path

try:
    import xml.etree.cElementTree as ET
except ImportError:
    import xml.etree.ElementTree as ET


class Signature:
    def GET(self):
        input_data = web.input(echostr=None)
        print '[GET]fullpath:' + web.ctx.fullpath 
        print 'echostr:' + input_data.echostr 

        return input_data.echostr

    def POST(self):
        post_data = web.input()
        data = web.data() 
        print '[signature.POST]'
        print post_data
        print data
        print '[POST]fullpath:' + web.ctx.fullpath 

        tree = ET.fromstring(data)
        content = tree.find('Content')
        content_str = content.text

        res_xml = ET.Element('xml')
        res_ToUserName = ET.SubElement(res_xml, 'ToUserName')
        res_ToUserName.text = tree.find('FromUserName').text
        res_FromUserName = ET.SubElement(res_xml, 'FromUserName')
        res_FromUserName.text = tree.find('ToUserName').text
        res_CreateTime = ET.SubElement(res_xml, 'CreateTime')
        res_CreateTime.text = '11'
        res_MsgType = ET.SubElement(res_xml, 'MsgType')
        res_MsgType.text = tree.find('MsgType').text
        res_Content = ET.SubElement(res_xml, 'Content')
        res_Content.text = content_str

        res_str = ET.tostring(res_xml)
        print 'res_str:' + res_str

        return res_str